package com.foreknow.demo3;

import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String answer = "";
        String name = "";
        String password = "";
        String loginname = "";
        String loginpassword = "";
        int card = 0;
        boolean isRight = false;
        boolean isRegister = false;
        do {
            System.out.println("**************************");
            System.out.println("1.  注册");
            System.out.println("2.  登录");
            System.out.println("3.  抽奖");
            System.out.println("**************************");
            System.out.println("请输入操作序号:");
            int choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("注册");
                    System.out.println("请输入用户名:");
                    name = input.next();
                    System.out.println("请输入密码:");
                    password = input.next();
                    card = (int) (Math.random() * 1000000 / 100);
                    System.out.println("用户名:" + name);
                    System.out.println("密码" + password);
                    System.out.println("卡号" + card);
                    isRegister = true;
                    break;
                case 2:
                    if (!isRegister) {
                        System.out.println("请先注册,然后登录");
                        System.out.println("是否继续y/n");
                        answer = input.next();
                        if ("y".equals(answer)) {
                            continue;
                        } else {
                            isRight = true;
                        }
                    } else {
                        for (int i = 1; i <= 3; i++) {
                            System.out.println("请输入登录用户名:");
                            loginname = input.next();
                            System.out.println("请输入登录密码:");
                            loginpassword = input.next();
                            if (loginname.equals(name) && loginpassword.equals(password)) {
                                System.out.println("Welcome" + name);
                                break;
                            } else if (i < 3){
                                System.out.println("您输入的用户名和密码不正确,还有" + (3 - i) + "次输入机会");
                            } else {
                                System.out.println("您输入三次密码都不正确!!!");
                            }
                        }
                        System.out.println("程序结束...");
                        isRight = false;
                    }
                    break;
                case 3:
                    System.out.println("抽奖功能暂未开放");
                    isRight = false;
                    break;
            }
        } while (!isRight);
    }
}